﻿using System.Linq;
using UniMana.Utils.Controls;

namespace UniMana.Data
{
    public class LeadershipInfo
    {
        #region /*Không thay đổi*/
        public bds m_bds = new bds();
        public void Save()
        {
            m_data.m_DCSave.SubmitChanges();
        }
        public void Delete()
        {
            m_bds.DeleteCurrent();
            m_data.m_DCSave.SubmitChanges();
        }
        #endregion /*Không thay đổi*/

        private DBMain m_data = new DBMain();
        #region [Properties - Thuộc tính]
        public Leadership Properties
        {
            get { return m_bds.Current as Leadership; }
        }
        #endregion

        public LeadershipInfo(int DefaultKey = 0)
        {
            var IQuery = m_data.m_DCSave.Leaderships.Where(tb => tb.LeadershipKey == DefaultKey);
            m_bds.DataSource = IQuery;
            var Row = IQuery.FirstOrDefault();
            if (Row == null)
            {
                Row = new Leadership();
                m_bds.Add(Row);
            }
        }

        /// <summary>
        /// Lấy 1 dòng với LeadershipRelationshipKey và khoa
        /// </summary>
        /// <param name="m_iDepartmentKey"></param>
        /// <param name="m_iLeaderRelationshipKey"></param>

        public LeadershipInfo(int m_iDepartmentKey,
            int m_iLeaderRelationshipKey)
        {
            var IQuery = m_data.m_DCSave.Leaderships.Where(tb => tb.LeadershipRelationshipKey == m_iLeaderRelationshipKey && tb.Catalogue_DepartmentKey == m_iDepartmentKey);
            m_bds.DataSource = IQuery;
            var Row = IQuery.FirstOrDefault();
            if (Row == null)
            {
                Row = new Leadership();
                m_bds.Add(Row);
            }
        }

        /// <summary>
        /// Lấy 1 dòng với LeadershipRelationshipKey
        /// </summary>
        /// <param name="m_iLeaderRelationshipKey"></param>
        /// <param name="GetOneRow"></param>

        public LeadershipInfo(int m_iLeaderRelationshipKey,
            string GetOneRow = "true")
        {
            var IQuery = m_data.m_DCSave.Leaderships.Where(tb => tb.LeadershipRelationshipKey == m_iLeaderRelationshipKey);
            m_bds.DataSource = IQuery;
            var Row = IQuery.FirstOrDefault();
            if (Row == null)
            {
                Row = new Leadership();
                m_bds.Add(Row);
            }
        }
    }
}
